package com.sd.activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;

import com.alex.log.ALog;
import com.sd.activity.r.R;
import com.sd.util.HtmlFinish;
import com.sd.util.WebUtil;
import com.sd.view.ToastManager;
import com.sd.view.ViewUtil;

/**
 * 
 * 
 * @author Alex.Lu
 * 
 */
public class CHLCardRechargeActivity extends BaseActivity implements
		OnClickListener, HtmlFinish {

	private ImageButton mReturn;

	private EditText mCardNOET;
	private EditText mCardValueET;
	private EditText mcardPasswordET;
	private Button mRechargeBT;
	private LinearLayout mWarmTipLL;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_recharge_chl);

		LinearLayout accountLL = (LinearLayout)findViewById(R.id.accountLL);
		accountLL.addView(ViewUtil.getAccountView(this, "account", "value"));
		mCardNOET = (EditText)findViewById(R.id.card_no);
		mCardValueET = (EditText)findViewById(R.id.card_value);
		mcardPasswordET = (EditText)findViewById(R.id.card_password);
		mRechargeBT = (Button)findViewById(R.id.recharge);
		mRechargeBT.setOnClickListener(this);
		mWarmTipLL = (LinearLayout)findViewById(R.id.warmtipLL);
		mWarmTipLL.addView(ViewUtil.getWarmTips(this, R.string.warmtip1));
		
		mReturn = (ImageButton) findViewById(R.id.return_btn);
		mReturn.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int v_id = v.getId();

		switch (v_id) {
		case R.id.return_btn:
			finish();
			break;
		case R.id.recharge:
			String cardNo = mCardNOET.getText().toString();
			String cardValue = mCardValueET.getText().toString();
			String password = mcardPasswordET.getText().toString();
			
			String postUrl = "http://wap.qidian.cn/wap2/pay/sdlPay_yibaoOk.do?&sid=" + BookStoreActivity.user;
			StringBuffer sbuf = new StringBuffer();
			sbuf.append("mtd=sdlPay_yibaoOk");
			sbuf.append("&pa7_cardAmt=");
			sbuf.append(cardNo);
			sbuf.append("&pa8_cardNo=");
			sbuf.append(cardValue);
			sbuf.append("&pa9_cardPwd=");
			sbuf.append(password);
			ALog.e("postUrl:"+postUrl);
			WebUtil.getHtml(this,this,postUrl,sbuf.toString());
			break;
		default:
			break;
		}
	}

	
	@Override
	public void onFinish(String html) {
		// TODO Auto-generated method stub
		ALog.e(html);
		if(html.equals("已提交，请关注账号余额变化。如有问题，请联系客服")){
			ToastManager.getInstance().showText(this, "已提交，请关注账号余额变化。如有问题，请联系客服");
		}else{
			ToastManager.getInstance().showText(this, R.string.msg_submit_fail);
		}
	}

}